<?php


namespace App\Helpers;


use App\Models\Order;
use Illuminate\Support\Carbon;
use Modules\Car\Entities\CarOrder;
use Modules\Car\Entities\ForbidLeaseDate;
use Modules\Car\Entities\RecognizeDrivingLicense;
use Yansongda\Pay\Pay;
trait Utils
{
    protected function getNewOrderModel(){
        return CarOrder::query()
            ->with('user','gear','customer','car',"customer");
    }
    //公共搜索选项
    protected function searchOrderModel($request){
        $model = CarOrder::query()
            ->with('user','gear','customer','car',"customer");
        if($request->filled('source')){
            $model = $model->where('source',$request->source);
        }
        if($request->filled('search')){
            $search = $request->search;
            $model = $model->where(function($query)use($search){
                $query->where('phone','like',$search.'%')
                    ->orWhere('wx_name','like',$search.'%')
                    ->orWhere('source','like',$search.'%')
                    ->orWhere('department',$search)
                    ->orWhere('nickname','like',$search.'%')
                    ->orWhere('customer_name','like',$search.'%')
                    ->orWhere('gear_car_name','like',$search.'%')
                    ->orWhere('plate_number','like',$search.'%');
            });
        }
        return $model;
    }
}
